#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char* memmove_wgc(char* a, char* b, int size);
char* strcat_wgc(char* a, char* b);
int strlen_wgc(char* data);
int atoi_wgc(char* a);
char* strncpy_wgc(char* a, char* b, int size);
int strncmp_wgc(char* a, char* b, int size);
int strlen_wgc(char* data)
{
        int i;
        for(i = 0;;)
        {
                if(*(data + i) == '\0')
                {
                        break;
                }
                i++;
        }
        return i;
}

char* memmove_wgc(char* a, char* b, int size)
{
	int i;
	for(i = 0; i < size; i++)
	{
		*(a + i) = *(b + i);
	}
	return a;
}
char* strcat_wgc(char* a, char* b)
{
	int i, j = 0;
	int size_a = 0, size_b = 0;
	size_a = strlen_wgc(a);
	size_b = strlen_wgc(b);
	int size = (size_a + size_b);
	for(i = 0; i < size; i++)
	{
			*(a + i) = *(b + j);
			j++;
	}
	return a;
}
int atoi_wgc(char* a)
{
	int i = 0, num = 0, j = 1, k = 0;
	int size = strlen(a);
	if((a[0] > 57 || a[0] < 48) && a[0] != 45 && a[0] != 43)
	{
		return 0;
	}
	for(i = 0; i < size; i++)
	{
		if((a[i] < 57 && a[i] > 48) || a[i] == 45 ||a[i] == 43)
		{
			j = j * 10;
		}
		else
		{
			break;
		}
	}
	if(a[0] == 45)
	{
		if(a[1] > 57 || a[1] < 48)
		{
			return 0;
		}
		j = j / 100;
		for(k = 1,i = i - 1; i >= 0; i--, k++)
		{
			num = num + (a[k] - 48) * j;
			j = j / 10;
		}
		num = num * -1;
		return num;
	}
	else
	{
		j = j / 10;
		printf("j = %d\n",j);
		for(k = 0,i = i - 1; i >= 0; i--, k++)
		{
			num = num + (a[k] - 48) * j;
			j = j / 10;
		}
		return num;
	}
	
}
char* strncpy_wgc(char* a, char* b, int size)
{
	for(int i = 0; i < size; i++)
	{
		*(a + i) = *(b + i);
	}
	return a;
}
int strncmp_wgc(char* a, char* b, int size)
{
	for(int i = 0; i < size; i++)
	{
		if(a[i] != b[i])
		{
			return a[i] - b[i];
		}
	}
}
int main()
{
	char a[3] = "ab";
	char a1[3] = "ab";
	char b[] = "abcdefgh";
	char c[] = "ffffffaaaaabbbbbcccccddddd";
	//memove_wgc函数测试
	printf("-----------------------------------------------\n");
	printf("b = %s\n",b);
	memmove_wgc(b, b + 3, 3);
	printf("memove_wgc函数测试：b = %s    （测试成功）\n",b);
	//strcat_wgc函数测试
	printf("-----------------------------------------------\n");
	printf("a = %s\n",a);
	printf("c = %s\n",c);
	strcat_wgc(a, c);
	printf("strcat_wgc函数测试：a = %s    （测试成功）\n",a);
	printf("b = %s\n",b);
	printf("c = %s\n",c);
	strcat_wgc(b, c);
	printf("strcat_wgc函数测试：b = %s    （测试成功）\n",b);
	//atoi_wgc函数测试
	printf("-----------------------------------------------\n");
	char names1[40] = "-37w724";
	char names2[40] = "37w724";
	char names3[40] = "-3e7w724";
	int num1 = atoi_wgc(names1);
	int num2 = atoi_wgc(names2);
	int num3 = atoi_wgc(names3);
	printf("names1 = %s\nnames2 = %s\nnames3 = %s\n",names1,names2,names3);
	printf("atoi_wgc函数测试：num1 = %d    （测试成功）\n",num1);
	printf("atoi_wgc函数测试：num2 = %d    （测试成功）\n",num2);
	printf("atoi_wgc函数测试：num3 = %d    （测试成功）\n",num3);
	//atoi函数测试
	printf("-----------------------------------------------\n");
	char names4[40] = "-e7w724";
	int num4 = atoi(names4);
	printf("%s\n",names4);
	printf("atoi函数测试：num4 = %d    （测试成功）\n",num4);
	//strncpy_wgc函数测试
	printf("-----------------------------------------------\n");
	char aaa[] = "abcd";
	char bbb[] = "bbbb";
	printf("aaa = %s\nbbb = %s\n",aaa,bbb);
	strncpy_wgc(aaa, bbb, 3);
	printf("strncpy_wgc函数测试：%s    （测试成功）\n",aaa);
	//strncmp_wgc函数测试
	printf("-----------------------------------------------\n");
	char ccc[] = "abce";
	char ddd[] = "agcf";
	int big = strncmp_wgc(ccc, ddd, 4);
	printf("ccc = %s\nddd = %s\n",ccc,ddd);
	printf("strncmp_wgc函数测试：%d    （测试成功）\n",big);
	return 0;
	
	
	
	
	/*char c[10] = "cdefgh";
	int a1 = sizeof(a);
	printf("%s\n",a);
	//strcat(a, c);
	int a2 = sizeof(a);
	printf("%s\na1=%d\na2=%d,\n",a,a1,a2);
	printf("%c\n",a[4]);
	printf("%c\n",c[5]);
	printf("%c\n",c[20]);
/*	a[20] = 'G';
	a[19] = 'F';
	a[18] = 'F';
	a[17] = 'F';
//	a[16] = 'F';
//	a[15] = 'F';
//	a[14] = 'F';
//	a[13] = 'F';
	for(int i = 0; i < 22; i++)
	{
		printf("%c",a[i]);
	}*/
	return 0;
}
